class DuplicatedInstanceError (Exception):
    def __init__(self, attrpath, value = None):
        '''
        Accept a dict of attribute and value pairs, or just one attribute and a value:
    
        Example:
           # user unique constraint has been violated (User.nick to be unique)
           DuplicatedInstanceError ('User.nick', 'jsmith')
 
           # student unique constraint has been violated (student nick's are fin for different schools)
           DuplicatedInstanceError ({
             'Student.nick'   : 'jsmith',
             'Student.school' : 'demo-primary-school'
           })
        '''
        self.attrpath = ''
        # accept a dict as the only parameter
        if isinstance (attrpath, dict):
            for (k, v) in attrpath.items():
                self.attrpath += ', ' + str (k) + ' = ' + str(v)
            self.attrpath = self.attrpath[2:]
        # accept a couple of strings
        else:
            self.attrpath = str(attrpath) + ' = ' + str(value) 
 
        self.attrpath = '(' + self.attrpath + ')'
        return

    def __str__ (self):
        return str (self.attrpath)